<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>业务管理</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
    <link rel="stylesheet" href="../../../admin/css/other/department.css"/>
    <link rel="stylesheet" href="../../../component/element-plus-2.7.8/package/dist/index.css"/>
    <link rel="stylesheet" href="../../../component/aieditor/style.css"/>
    <style>
        .ztree li span.button.diy01_ico_open {
            margin-right: 2px;
            background: url(../../../admin/images/parent-open.png) no-repeat scroll 0 0 transparent;
            background-size: 16px 16px;
            vertical-align: top;
        }

        .ztree li span.button.diy01_ico_close {
            margin-right: 2px;
            background: url(../../../admin/images/parent.png) no-repeat scroll 0 0 transparent;
            background-size: 16px 16px;
            vertical-align: top;
        }

        .ztree li span.button.diy01_ico_docu {
            margin-right: 2px;
            background: url(../../../admin/images/sub.png) no-repeat scroll 0 0 transparent;
            background-size: 15px 15px;
            vertical-align: top;
        }

        .busGroupTree {
            overflow: hidden;
        }

        .busGroupTree:hover {
            overflow-y: auto;
        }

        .bus-rigth {

        }

        .bus-rigth .entity {
            padding: 30px 0px 30px 0px;
            width: 100%;
            background-color: #fff;
            border-radius: 5px; /* 设置圆角大小 */
            border: dashed 1px #ccc; /* 设置虚线样式及颜色 */
            display: flex; /* 设置容器为flex布局 */
            align-items: center; /* 在交叉轴上对齐项目 */
            justify-content: center; /* 水平居中 */
            flex-direction: column; /*垂直排列*/
            /* 设置动画效果 */
            -webkit-transform: scale(0.95);
            -moz-transform: scale(0.95);
            -o-transform: scale(0.95);
            -webkit-transition-duration: 0.5s;
            -moz-transition-duration: 0.5s;
            -o-transition-duration: 0.5s;
            cursor: pointer;
        }

        .bus-rigth .entity:hover {
            -webkit-transform: scale(1.0);
            -webkit-box-shadow: 0px 0px 5px #ccc;
            -moz-transform: scale(1.0);
            -moz-box-shadow: 0px 0px 5px #ccc;
            -o-transform: scale(1.0);
            -o-box-shadow: 0px 0px 5px #ccc;
            border: dashed 1px #999; /* 设置虚线样式及颜色 */
            background-color: #fffdef;
        }

        .bus-rigth .entity .title {
            text-align: center;
            font-size: 18px;
            font-weight: bold;
            color: #1e9fff;
            width: 70%;
        }

        .bus-rigth .entity .name {
            text-align: center;
            font-size: 16px;
            font-weight: bold;
            color: #000;
            width: 70%;
        }

        .bus-rigth .del {
            position: absolute;
            top: 5px;
            right: 5px;
            display: block;
            color: #5FB878;
            text-align: center;
            cursor: pointer;
        }

        .bus-rigth .edit {
            position: absolute;
            bottom: 0px;
            right: 5px;
            display: block;
            color: #1e9fff;
            text-align: center;
            cursor: pointer;
        }

        .bus-rigth .del i {
            font-size: 23px;
        }

        .bus-rigth .edit i {
            font-size: 23px;
        }

        .bus-rigth .checked {
            -webkit-transform: scale(1.0);
            -webkit-box-shadow: 0px 0px 5px #ccc;
            -moz-transform: scale(1.0);
            -moz-box-shadow: 0px 0px 5px #ccc;
            -o-transform: scale(1.0);
            -o-box-shadow: 0px 0px 5px #ccc;
            border: dashed 1px #999; /* 设置虚线样式及颜色 */
            background-color: #fffdef;
        }

        .pages {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            padding: 10px; /* 内边距 */
        }
    </style>
</head>
<body class="pear-container">

<div class="layui-row layui-col-space6">
    <div class="layui-col-xs3 ">
        <div class="layui-card" id="contextmenu">
            <div class="layui-card-header" style="white-space: nowrap;overflow: hidden;">模型分类（右键操作，拖动排序）
            </div>
            <div class="layui-card-body busGroupTree" style="height: 89vh;">
                <ul id="busGroupTree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="layui-col-xs9 bus-rigth" id="business_model" style="display: none">
        <add-bus-model :edit="$options.myOptions.edit" :select_group_id="selectGroupId" v-if="isAdd"
                       @update_is_add="closeAddWin"></add-bus-model>
        <update-bus-model :edit="$options.myOptions.edit" :update_data="editItem" v-if="isUpdate"
                          @update_is_update="closeUpdateWin"></update-bus-model>
        <bus-model-manage ref="busModelManage" :show="isBusModelManage"  :bus_model="ck_businessModel" v-if="isBusModelManage"
                          @update_is_bus_model_manage="closeBusModelManageWin" @add_table="add_table"></bus-model-manage>

        <table-design :bus="ck_businessModel" :show="isTableDesign" v-if="isTableDesign" @up-parent="upParent"></table-design>
        <div class="layui-card">
            <div class="layui-card-header">

                <div style="display: inline-block">
                    <el-breadcrumb separator="/">
                        <el-breadcrumb-item>业务模型</el-breadcrumb-item>
                        <el-breadcrumb-item v-for="(item,index) in selectGroup" :key="item.id">{{item.group_name}}
                        </el-breadcrumb-item>
                    </el-breadcrumb>
                </div>
                <div style="display: inline-block" v-if="selectGroup.length>0">
                    <i @click="getBusAll()" class="layui-icon layui-icon-close-fill"
                       style="color: red;cursor: pointer;font-size: 18px;"></i>
                </div>
                <div style="display: inline-block;float: right;">
                    <button class="pear-btn pear-btn-primary pear-btn-sm" type="button"
                            @click="isAdd=true">新增
                    </button>
                </div>

                <div style="display: inline-block;float: right;padding-right: 5px;">
                    <button type="button" class="pear-btn pear-btn-sm" @click="queryBus">
                        <i class="layui-icon layui-icon-search"></i>
                    </button>
                </div>
                <div style="display: inline-block;float: right;padding-right: 5px;">
                    <el-input :clearable="true" v-model="queryBusModel.query" placeholder="关键字查询"></el-input>
                </div>
            </div>
            <div class="layui-card-body" style="height: 89vh " v-if="businessModels.length>0">
                <div class="layui-row layui-col-space4" style="max-height:85vh;overflow-y:auto">
                    <div class="layui-col-xs2" v-for="(item,index) in businessModels" :key="item.id">
                        <div :class="['entity',item.checked?'checked':'']" @click="open(item)">
                            <div class="title layui-elip">{{item.bus_title}}</div>
                            <div class="name layui-elip">{{item.bus_name}}</div>
                        </div>
                        <div class="del" @click="deleteBus(item)"><i class="layui-icon layui-icon-clear"></i></div>
                        <div class="edit" @click="editBus(item)"><i class="layui-icon layui-icon-edit"></i></div>
                    </div>
                </div>
                <div class="pages">
                    <el-pagination @prev-click="getBusListPrev" @next-click="getBusListNext"
                                   @current-change="getBusListByPage" background layout="prev, pager, next"
                                   :total="total" :page-size="queryBusModel.limit"/>
                </div>
            </div>
            <div class="layui-card-body" style="height: 90vh;" v-else>
                <el-empty description="还没有业务模型"/>
            </div>
        </div>
    </div>
</div>

<script src="../../../component/vue/vue.global.js"></script>
<script src="../../../config/apiUrl.js"></script>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script src="../../../component/vue/vue.global.js"></script>
<script src="../../../component/vue/httpVueLoader.js"></script>
<script src="../../../component/element-plus-2.7.8/package/dist/index.full.min.js"></script>
<script src="../../../component/element-plus-2.7.8/icons-vue.js"></script>
<script>
    var vue_business_model;
</script>
<script type="module">
    import {AiEditor} from '../../../component/aieditor/index.js'
    const {createApp, defineAsyncComponent, nextTick} = Vue;
    const {ElMessageBox} = ElementPlus;
    vue_business_model = createApp({
        data() {
            return {
                businessModels: [],
                ck_businessModel: {},
                isAdd: false,
                isUpdate: false,
                isTableDesign: false,
                isBusModelManage: false,
                queryBusModel: {
                    limit: 20,
                    page: 1,
                    groups: "",
                    query: ""
                },
                total: 0,
                selectGroup: [],
                selectGroupId: "",
                editItem: {}
            }
        },
        myOptions: {
            edit: {
                class: AiEditor
            }
        },
        updated: function () {
            layui.form.render();
        },
        methods: {
            open(item) {
                this.ck_businessModel.checked = false;
                item.checked = true;
                this.ck_businessModel = item;
                this.isBusModelManage = true;
            }
            , closeAddWin() {
                this.isAdd = false;
                this.queryBusModel.page = 1;
                this.businessModels = [];
                this.getBusList()
            }
            , closeUpdateWin() {
                this.isUpdate = false;
                this.queryBusModel.page = 1;
                this.businessModels = [];
                this.getBusList()
            }
            , closeBusModelManageWin() {
                this.isBusModelManage = false;
                this.ck_businessModel.checked = false
            }
            , async getBusList() {
                let res_data = await layui.common.ajax({
                    url: apiUrlConfig.businessModel.getList,
                    data: this.queryBusModel,
                    contentType: 'application/x-www-form-urlencoded'
                })
                this.total = res_data.data.total;
                this.businessModels = [];
                this.businessModels = res_data.data.records;
            }
            , queryBus() {
                this.queryBusModel.page = 1;
                this.getBusList()
            }
            , getBusAll() {
                this.queryBusModel.groups = "";
                this.queryBusModel.page = 1;
                this.businessModels = [];
                this.selectGroup = [];
                this.getBusList()
            }
            , getBusListByPage(page) {
                this.queryBusModel.page = page;
                this.getBusList();
            }
            , getBusListPrev(page) {
                this.queryBusModel.page = page;
                this.getBusList();
            }
            , getBusListNext(page) {
                this.queryBusModel.page = page;
                this.getBusList();
            }
            , deleteBus(item) {
                let that = this;
                ElMessageBox.confirm('确定删除吗？', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确认',
                    type: 'warning',
                })
                    .then(async () => {
                        let res_data = await layui.common.ajax({
                            url: apiUrlConfig.businessModel.delete,
                            data: JSON.stringify([item.id])
                        })
                        this.queryBusModel.page = 1;
                        this.businessModels = [];
                        that.getBusList();
                        layui.toast.success({title: false, message: '删除成功'})
                    })
                    .catch(() => {
                        // catch error
                    })
            }
            , editBus(item) {
                this.isUpdate = true;
                this.editItem = item;
            }
            ,add_table(id){
                this.isTableDesign = true;
            }
            ,upParent(data,event){
                this[data.key] = data.value;
                if(event != undefined && event!=null){
                    eval(event.eval);
                }
            }
        },
        mounted() {
            this.getBusList()
        },
        watch: {}
    })
        .use(ElementPlus)
        .component('update-bus-model', defineAsyncComponent(httpVueLoader('./vue/updateBusModel.vue')))
        .component('add-bus-model', defineAsyncComponent(httpVueLoader('./vue/addBusModel.vue')))
        .component('bus-model-manage', defineAsyncComponent(httpVueLoader('./vue/busModelManage.vue')))
        .component('table-design', defineAsyncComponent(httpVueLoader('./vue/tableDesign.vue')))
</script>
<script>
    layui.use(['jquery', 'common', 'toast', 'busGroup'], function () {
        //先挂载vue 这样vue里面就可使用 layui的函数
        vue_business_model = vue_business_model.mount('#business_model')
        layui.jquery("#business_model").show();
        let busGroup = layui.busGroup;
        let common = layui.common;
        var lay = layui.lay;

        let busGroupTree;

        async function getList() {
            let d = await common.ajax({
                url: apiUrlConfig.businessGroup.getListAll
            })
            busGroupTree = busGroup.init({
                treeId: "busGroupTree",
                contextmenu: "contextmenu",
                zNodes: d.data.map(item => {
                    item.iconSkin = "diy01";
                    return item;
                })
            })
        }

        getList();
        //刷新业务分组
        try {
            const bc = new BroadcastChannel('business_group_reload');
            bc.onmessage = async function (e) {
                console.log(busGroupTree)

                let d = await common.ajax({
                    url: apiUrlConfig.businessGroup.getListAll
                })
                busGroupTree.setData(d.data.map(item => {
                    item.iconSkin = "diy01";
                    return item;
                }));
            };
        } catch (e) {

        }
    })
</script>
</body>
</html>
